//记录插入图片的数量
var picCount = 0;
//上传图片
function uploadPic() {
    var picFile = "<input  name=\"pic" + picCount +
        "\"\"class=\"avatarUpload\"  onchange=\"insertPic()\" type=\"file\" style=\"width: 0;height: 0\"\n" +
        "accept=\".jpg,.png,.jepg,.tiff\">"
    $(".blogContent").append(picFile);
    $("input[name='pic" + picCount + "']").click();
}
//动态加载图片
function insertPic() {
    var img = "<img id='" + picCount + "'style=\"max-width: 100%\"><div><br></div>";
    var file = $("input[name='pic" + picCount + "']").prop("files");
    $(".writing_area").append(img);
    $("#" + picCount).attr('src', window.URL.createObjectURL(file[0]));
    picCount++;
}
//发表博客时根据博客内容动态生成表单然后提交给后端
function publishBlog() {
    var title=$(".blogTitle").val();
    var blog = '';
    var introduction = '';
    //博客标题
    var input = "<input name='title' width='0' type='text' value='" + title + "'>";
    //找到隐藏的博客表达
    $(".blogContent").append(input);
    var introduction_children = $(".introduction_area").children();
    for (var i = 0; i < introduction_children.length; i++) {
        introduction = introduction_children[i].textContent;
        blog = "picture:" + introduction_children[i].id;
        //博客简介
        var input = "<input name='introduction' type='text' value='" + introduction + "'>";
        $(".blogContent").append(input);
    }
    var children = $(".writing_area").children();
    for (var i = 0; i < children.length; i++) {
        if (children[i].tagName == "DIV") {
            blog = children[i].textContent;
        } else {
            blog = "picture:" + children[i].id;
        }
        //博客的文本内容
        var input = "<input name='blog' width='0' type='text' value='" + blog + "'>";
        $(".blogContent").append(input);
    }
     $(".blogContent").submit();
}
